using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public float movespeed = 8f;
    private float h;
    private SpriteRenderer sr;
    private Rigidbody2D r; 
    // Start is called before the first frame update
    void Start()
    {
        sr = GetComponent<SpriteRenderer>();
        r= this.GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        h = Input.GetAxis("Horizontal");
        //this.transform.Translate(movespeed * Time.deltaTime * Vector3.right * h);
        r.velocity = new Vector2(h * movespeed, r.velocity.y);
        if (h > 0)
        {
            sr.flipX = false;
        }
        else if (h < 0)
        {
            sr.flipX = true;

        }
        if(Input.GetKeyDown(KeyCode.Space))
        {
            GameObject obj = Instantiate(Resources.Load<GameObject>("BullentObj"),this.gameObject.transform.position+ new Vector3(sr.flipX ? -0.3f : 0.3f, 0.3f, 0), Quaternion.identity);
            obj.AddComponent<Bullent>().ChangeMoveDir(sr.flipX?Vector3.left:Vector3.right);
        }
        if(Input.GetKeyDown(KeyCode.J))
        {
            r.AddForce(Vector2.up * 300);
        }
    }
}
